<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="Entidades.*, JDBC.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Procesando Cotizacion</title>
    </head>
    <body>
        <%
            Insertar ins = new Insertar();
            Seleccionar sel = new Seleccionar();
            Cliente cli;
            TarjetaCredito tc;
            Cotizacion cot;
            long tc_id_bd=0;
            long cliente_id_bd=0;
            long cot_id_bd=0;
            
            Date fechaActual = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy' 'HH:mm:ss ");
            String fechaCot = sdf.format(fechaActual);
            //out.print("Fecha actual: "+fechaCot);
            
            //Los datos de la tarjeta de credito
            if( request.getParameter("numTarjeta") != null && request.getParameter("numTarjeta") != "" &&
                request.getParameter("mesV") != null && request.getParameter("mesV") != "" &&
                request.getParameter("anioV") != null && request.getParameter("anioV") != "" &&
                request.getParameter("numSeg") != null && request.getParameter("numSeg") != "" ){
            
                tc = new TarjetaCredito(Long.parseLong(request.getParameter("numTarjeta")), request.getParameter("mesV"), request.getParameter("anioV"), Integer.parseInt(request.getParameter("numSeg")));
                ins.insertaDatosTarjetaCredito(tc);
                tc_id_bd = sel.obtenTarjetaCreditoId(request.getParameter("numTarjeta"), request.getParameter("mesV"),request.getParameter("anioV"),request.getParameter("numSeg"));
            }
            
            //los datos del usuario
            if( request.getParameter("nombre") != null && request.getParameter("nombre") != "" &&
                request.getParameter("ap_p") != null && request.getParameter("ap_p") != "" &&
                request.getParameter("ap_m") != null && request.getParameter("ap_m") != "" &&
                request.getParameter("rfc") != null && request.getParameter("rfc") != "" &&
                request.getParameter("emailC") != null && request.getParameter("emailC") != "" &&
                request.getParameter("direccion") != null && request.getParameter("direccion") != "" ){
                
                cli = new Cliente(request.getParameter("nombre"), request.getParameter("ap_p"), request.getParameter("ap_m"), request.getParameter("rfc"), request.getParameter("emailC"), request.getParameter("direccion"));
                ins.insertaDatosCliente(cli,tc_id_bd);
                cliente_id_bd = sel.obtenerClienteId(request.getParameter("nombre"),request.getParameter("ap_p"),request.getParameter("ap_m"),tc_id_bd);
            }
            
            if( request.getParameter("anioV") != null && request.getParameter("") != "" &&
                request.getParameter("codigoPostal") != null && request.getParameter("codigoPostal") != "" &&
                request.getParameter("edadC") != null && request.getParameter("edadC") != "" &&
                request.getParameter("precio") != null && request.getParameter("precio") != "" &&
                request.getParameter("tipoSeguro") != null && request.getParameter("tipoSeguro") != "" &&
                request.getParameter("marca") != null && request.getParameter("marca") != ""  &&
                request.getParameter("modelo") != null && request.getParameter("modelo") != "" &&
                request.getParameter("estadoRep") != null && request.getParameter("estadoRep") != ""
              ){
                long costoSeguro = sel.obtenCostoSeguro(Long.parseLong(request.getParameter("precio")));
                cot = new Cotizacion(Integer.parseInt(request.getParameter("anioV")), Integer.parseInt(request.getParameter("codigoPostal")), Integer.parseInt(request.getParameter("edadC")),costoSeguro );
                ins.insertaDatosCotizacion(cot,Long.parseLong(request.getParameter("estadoRep")), Long.parseLong(request.getParameter("modelo")), Long.parseLong("tipoSeguro"), cliente_id_bd, Long.parseLong("precio"));
            
            
            }
            
        
        %>
        <div>
            <center>
                <h1>Se agregó la cotizacion</h1>
                <h3><a href="../index.jsp">Volver al inicio</a></h3>
            </center>
        </div>
    </body>
</html>
